﻿@model iDMS.Models.Sheet
@{
    ViewBag.Title = "Sheet Upload";
}
<h3>
    @Html.Partial("_SheetTitle", Model) - <span class="accent">Upload</span>
</h3>
<script type="text/javascript">
    $(document).ready(function () {
        $("#fileInput").uploadify({
            'swf': '/Scripts/uploadify.swf',
            'uploader': '/Drawing/Upload/@Model.ScheetID',
            'cancelImg': '/Content/Images/cancel.png',
            'multi': false,
            'buttonText': 'Upload PDF or TIFF file...',
            'fileTypeExts': '*.pdf; *.tif; *.tiff',
            'width': 200,
            'onUploadStart': function (file) {
                $("#sheetRes").html('Processing data...');
            },
            'onUploadSuccess': function (file, data, response) {
                $("#sheetInfoText").html(data);
                $('#sheetInfoPanel').fadeIn('slow').delay(4000).fadeOut('slow');
                sheetRes();
            }
        });
        $("#fileInput2").uploadify({
            'swf': '/Scripts/uploadify.swf',
            'uploader': '/Drawing/UploadAttachment/@Model.ScheetID',
            'cancelImg': '/Content/Images/cancel.png',
            'multi': true,
            'buttonText': 'Upload attachment files...',
            'width': 200,
            'fileSizeLimit': 0,
            'onUploadSuccess': function (file, data, response) {
                $("#attachInfoText").html(data);
                $("#attachInfoPanel").show();
                sheetAtt();
            }
        });
    });

    function sheetAtt() {
        $.ajax({
            type: "GET",
            url: "/Drawing/AttachmentsWindow/?id=@Model.ScheetID",
            global: false,
            cache: false,
            dataType: 'html',
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                $("#attachm_list").html(errorThrown);
            },
            success: function (data, textStatus, XMLHttpRequest) {
                $("#attachm_list").html(data);
            }
        });
    }

    function sheetRes() {
        $.ajax({
            type: "GET",
            url: "/Drawing/SheetResource/?id=@Model.ScheetID",
            global: false,
            cache: false,
            dataType: 'html',
            beforeSend: function () {
                $("#sheetRes").html('Retrieving data...');
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                $("#sheetRes").html(errorThrown);
            },
            success: function (data, textStatus, XMLHttpRequest) {
                $("#sheetRes").html(data);
            }
        });
    }    
</script>
<fieldset>
    <legend>Sheet</legend>
    <div class="ui-widget">
        <div class="ui-state-highlight ui-corner-all" style="margin-top: 20px; padding: 0 .7em;">
            <p id="sheetRes">
                @Html.Action("SheetResource", new { id = Model.ScheetID })
            </p>
        </div>
    </div>
    <div id="fileInput">
    </div>
    <div class="ui-widget" id="sheetInfoPanel" style="display: none">
        <div class="ui-state-highlight ui-corner-all" style="margin-top: 20px; padding: 0 .7em;">
            <p>
                <span class="ui-icon ui-icon-info" style="float: left; margin-right: .3em;"></span>
                <strong>Hey!</strong> <span id="sheetInfoText">info</span></p>
        </div>
    </div>
</fieldset>
<fieldset>
    <legend>Sheet Attachments </legend>
    @if (Model.InformationCarrier.isAttachmentRequired)
    {
        <div class="ui-widget">
            <div class="ui-state-error ui-corner-all" style="margin-top: 20px; margin-bottom: 20px;
                padding: 0 .7em;">
                <p>
                    <span class="ui-icon ui-icon-notice" style="float: left; margin-right: .3em;"></span>
                    Information Carrier:<strong> @Model.InformationCarrier.Name </strong>require to
                    upload a <strong>*.@Model.InformationCarrier.AttachmentExtension </strong>file
                </p>
            </div>
        </div>
    }
    <div id="fileInput2">
    </div>
    <div class="ui-widget" id="attachInfoPanel">
        <div class="ui-state-highlight ui-corner-all" style="margin-top: 20px; padding: 0 .7em;
            display: none">
            <p>
                <span class="ui-icon ui-icon-info" style="float: left; margin-right: .3em;"></span>
                <strong>Hey!</strong> <span id="attachInfoText">info</span></p>
        </div>
    </div>
    <div id="attachm_list">
        @Html.Action("AttachmentsWindow", new { id = Model.ScheetID })
    </div>
</fieldset>
@Html.ActionLink("Back to List", "Sheets", new { id = Model.DrawingID }, new { @class = "btl" })
